html, body, #app, .app-container {
  width: 100%;
  min-height: 100%;
  background: $bg-color;
}

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
  font-family: 'Roboto', sans-serif;
}

a {
  text-decoration: none;
  color: $basic-dark-color;

  &:hover {
    color: darken($color: $basic-dark-color, $amount: 10%)
  }
}

.pi-modal {
  display: none;
  position: fixed;
  z-index: 3;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  overflow: auto;
  background: rgba(0, 0, 0, 0.4);
  animation: fade-in 0.4s;

  .pi-modal-dialog {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    top: 0;
    max-width: 90%;
    max-height: 90%;
    margin: auto;
    background: #fefefe;
    animation: fade-in 0.4s;
  }
}

body.pi-modal-open {
  height: 100vh;
  overflow-y: hidden;
  padding-right: 15px;
  position: fixed;

  .pi-modal {
    display: block;
  }
}

.text-right {
  text-align: right;
}

.language-picker {
  position: relative;
  margin: 4px 8px 0 0;

  .current {
    cursor: pointer;
  }

  ul {
    display: none;
    background: #f5f5f6;
    border: none;
    margin: 0;
    padding: 0;
    overflow: hidden;
    border-radius: 3px 0 3px 3px;
    background-clip: padding-box;
    margin-bottom: 5px;
    position: absolute;
    top: 100%;
    right: 0;

    li {
      cursor: pointer;
      border-bottom: 1px solid #ebebeb;
      padding: 10px 20px;
      margin: 0;
      outline: 0;
      color: #7d8086;
      display: flex;
      flex-direction: row;
      align-items: center;

      span {
        padding-left: 8px;
      }

      &:hover {
        background: rgba(235, 235, 235, 0.9);
        color: #737881;
      }
    }

    &.open {
      display: block;
    }
  }
}

.language-icon {
  height: 16px;
  width: 16px;
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.app-container {
  flex: 1;
  position: relative;
}

.pi-notifications {
  position: fixed;
  display: flex;
  align-items: flex-end;
  flex-direction: column;
  right: 2em;
  bottom: 2em;

  .pi-item {
    box-sizing: border-box;
    display: flex;
    flex-direction: row;
    align-items: center;
    text-align: left;
    padding: 0.8em;
    background-color: $bg-color;
    max-width: 500px;
    position: relative;
    box-shadow: 1px 7px 14px -5px rgba(0,0,0,0.2);

    &+& {
      margin-top: 1em;
    }

    &.success:before {
      background-color: #2BDE3F;
    }

    &.error:before {
      background-color: #e7431a;
    }

    &.info:before {
      background-color: #1D72F3;
    }

    &.warning:before {
      background-color: #FFC007;
    }

    &:before {
      content: '';
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 2px;
    }

    .pi-details {
      flex: 1;

      .pi-title {
        color: #3e3e3e;
        font-weight: 700;
        margin-top: 0;
        margin-bottom: 8px;
      }

      .pi-description {
        font-size: 14px;
        margin-top: 0;
        margin-bottom: 0;
        color: #878787;
      }
    }

    .pi-close {
      width: 14px;
      cursor: pointer;
      height: 14px;
      fill: #878787;
      margin-left: 1.2em;
      background: url('../images/close.svg') no-repeat center center;
    }
  }

  @media screen and (max-width: $breakpoint-tablet) {
    right: 0;
    left: 0;
    bottom: 0;

    .pi-item {
      max-width: 100%;
      width: 100%;
    }
  }
}

.app-container, #app {
  display: flex;
  flex-direction: column;
}

.app-content {
  display: flex;
  flex-direction: column;
  flex-grow: 1;
  padding: 0 2em;
}

.app-title {
  display: flex;
  position: relative;
  align-items: center;
}

.app-header {
  display: flex;
  flex-direction: row;
  padding: 0 2em;
  margin-bottom: 1em;
  align-items: center;
  justify-content: space-between;
  background: $header-color;
  position: relative;
  z-index: 2;

  h1 {
    white-space: nowrap;
    font-size: 2rem;
  }

  @media screen and (max-width: $breakpoint-tablet) {
    padding: 0 1em;

    h1 {
      display: none;
    }
  }
}

.pi-center {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-grow: 1;
}

.app-footer {
  font-size: 0.8em;
  padding: 1em 0;
  background: $footer-color;
  display: flex;
  flex-direction: row;

  .pi-menu {
    margin: 0 auto;
    max-width: 1000px;
    column-width: 300px;
    display: block;

    .pi-item {
      display: block;
      padding: 1em 2em;
    }
  }
}

.app-menu {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  padding: 0;
  margin: 0;
  width: 300px;
  max-width: 100%;
  background: lighten($header-color, 15%);
  transform: translateX(-100%);
  transition: all 0.1s ease;
  padding-top: 85px;
  z-index: 1;

  &.is-open {
    transform: none;
    box-shadow: $menu-shadow-size 0px $menu-shadow-size (-$menu-shadow-size) rgba(0, 0, 0, 0.2);
  }

  .app-menu-content {
    overflow-y: auto;
    height: 100%;
  }

  .pi-menu {
    display: flex;
    flex-direction: column;
    list-style: none;

    > .pi-item {
      flex: 1;
      margin: 1px 0;

      > a {
        display: block;
        border-left: 5px solid $header-color;
        padding: 1em;

        &:hover {
          border-left-color: $menu-color;
        }
      }
    }
  }
}

.pi-spinner {
  position: relative;
  width: $basic-spinner-dimensions;
  height: $basic-spinner-dimensions;
  font-size: 0;

  &:before,
  &:after {
    content: "";
    display: block;
    position: absolute;
    border-width: 4px;
    border-style: solid;
    border-radius: 50%;
  }

  @keyframes rotate-animation {
    0% {
      transform: rotate(0deg);
    }

    100% {
      transform: rotate(360deg);
    }
  }

  @keyframes anti-rotate-animation {
    0% {
      transform: rotate(0deg);
    }

    100% {
      transform: rotate(-360deg);
    }
  }

  &:before {
    width: $main-spinner-dimensions;
    height: $main-spinner-dimensions;
    border-bottom-color: $basic-dark-color;
    border-right-color: $basic-dark-color;
    border-top-color: rgba($basic-dark-color, 0);
    border-left-color: rgba($basic-dark-color, 0);
    top: 0;
    left: 0;
    animation: rotate-animation 1s linear 0s infinite;
  }

  &:after {
    width: $small-spinner-dimensions;
    height: $small-spinner-dimensions;
    border-bottom-color: $basic-dark-color;
    border-right-color: $basic-dark-color;
    border-top-color: rgba($basic-dark-color, 0);
    border-left-color: rgba($basic-dark-color, 0);
    top: ($main-spinner-dimensions - $small-spinner-dimensions) / 2;
    left: ($main-spinner-dimensions - $small-spinner-dimensions) / 2;
    animation: anti-rotate-animation 0.85s linear 0s infinite;
  }
}

$tile-height: 70px;
$tile-width: 70px;
$tile-gap: 10px;

.pi-content {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.pi-dashboard {
  flex: 1;
  position: relative;
  display: grid;
  grid-template-columns: repeat(auto-fit, $tile-width);
  grid-template-rows: repeat(auto-fit, $tile-height);
  grid-gap: $tile-gap;
  overflow: visible;

  .pi-tile {
    display: flex;
    position: relative;

    &.small {
      grid-column: span 1;
      grid-row: span 1;
      width: $tile-width;
      height: $tile-height;
    }

    &.medium {
      grid-column: span 2;
      grid-row: span 2;
      width: 2 * $tile-width + 1 * $tile-gap;
      height: 2 * $tile-height + 1 * $tile-gap;
    }

    &.wide {
      grid-column: span 4;
      grid-row: span 2;
      width: 4 * $tile-width + 3 * $tile-gap;
      height: 2 * $tile-height + 1 * $tile-gap;
    }

    &.large {
      grid-column: span 4;
      grid-row: span 4;
      width: 4 * $tile-width + 3 * $tile-gap;
      height: 4 * $tile-height + 3 * $tile-gap;
    }

    &:hover {
      outline: rgba(29, 29, 29, 0.1) solid 4px;
    }
  }
}

.pi-search {
  position: relative;
  flex: 1;
  display: flex;
  justify-content: center;

  input[type=search] {
    font-size: 1em;
    border: 1px solid transparent;
    background-color: #f1f1f1;
    padding: 10px;
    font-size: 16px;
    max-width: 80%;
    width: 250px;
    box-sizing: border-box;
    transition: width ease 0.1s;

    @media screen and (max-width: $breakpoint-mobile) {
      width: 100px;
    }
  }

  &:focus-within input[type=search] {
    width: 90%;
    max-width: 90%;

    & + .pi-details:not(:empty) {
      display: block;
      opacity: 1;
    }
  }

  .pi-details {
    display: none;
    opacity: 0;
    position: absolute;
    z-index: 2;
    top: 100%;
    width: 90%;
    box-sizing: border-box;
    background: #f0f0f0;
    padding: 1px;
    transition: all 0.1s 0.1s ease;
  }

  .pi-item {
    display: block;
    padding: 10px;
    cursor: pointer;
    background-color: white;
    border-bottom: 1px solid #d4d4d4;
  }

  .pi-item:hover {
    background-color: #e9e9e9;
  }

  .pi-center {
    padding: 30px;
    background-color: white;
  }
}

.form-row {
  margin: 1em;

  label {
    display: block;
    margin-bottom: 0.2em;
  }

  input {
    padding: 0.3rem;
    font-size: 1rem;
  }

  button {
    padding: 0.5em 1em;
    border: 1px solid black;
    font-weight: bold;
    border-radius: 4px;
    cursor: pointer;
  }

  button:disabled {
    border: 1px solid #ccc;
    color: #ccc;
    cursor: default;
  }
}

.pi-error {
  > img {
    width: 600px;
    max-width: 100%;
    margin: 1em 0;
  }

  .pi-title {
    color: $basic-dark-color;
    display: block;
    font-size: 1.5em;
  }

  .pi-description {
    display: block;
    margin: 0.5em 0;
  }

  .pi-details {
    display: block;
    margin: 0.5em 0;
    color: #3e3e3e;
    font-size: 0.8em;
  }
}

.app-user {
  position: relative;

  .app-user-avatar {
    display: flex;
    align-items: center;
    white-space: nowrap;
    cursor: pointer;

    img {
      position: relative;
      overflow: hidden;
      width: 32px;
      min-width: 32px;
      height: 32px;
      border-radius: 50% !important;
      vertical-align: middle;
      border-style: none;
      box-sizing: border-box;
      line-height: 1;
      margin-right: 0.5em;
    }

    &::after {
      display: inline-block;
      box-sizing: border-box;
      height: 8px;
      width: 8px;
      border-style: solid;
      border-color: black;
      border-width: 0px 2px 2px 0px;
      position: relative;
      transform: rotate(45deg);
      transition: opacity 150ms ease-in-out;
      content: '';
    }
  }

  .app-user-details {
    display: none;
    list-style: none;
    position: absolute;
    background: white;
    padding: 0;
    right: 0;
    border: 1px solid #ececec;
    border-radius: 3px;
    top: 40px;
    cursor: default;

    li {
      display: block;
      padding: 10px;
      max-width: 300px;
      text-overflow: ellipsis;
      overflow: hidden;
      white-space: nowrap;
      text-align: right;

      & > a {
        display: block;
      }

      &.sep {
        border-bottom: 1px solid #ccc;
        padding: 0;
      }

      .user-name {
        font-weight: bold;
        color: #666;
        display: block;
        font-size: 0.6em;
      }
    }

    &:before, &:after {
      content: '';
      display: block;
      position: absolute;
      bottom: 100%;
      width: 0;
      height: 0;
    }

    &:before {
      right: 27px;
      border: 6px solid transparent;
      border-bottom-color: #ececec;
    }

    &:after {
      right: 28px;
      border: 5px solid transparent;
      border-bottom-color: #fff;
    }
  }

  &.is-open {
    img {
      opacity: 0.8;
    }

    .app-user-details {
      display: block;
    }

    &::after {
      opacity: 0.2;
    }
  }
}
